﻿<#
#=======================================================================================
# Name: BuildMediaFolder.ps1
# Version: 0.2
# Author: Raphael Perez - raphael@rflsystems.co.uk
# Date: 10/01/2013
# Comment: This script will create the folder structure with all files needed to implement the SCCM 2012 SP1 infrastructure
# 
# Updates:
#        0.1 - Raphael Perez - 05/10/2012 - Initial Script
#        0.2 - Raphael Perez - 10/01/2013
#					   - Updated Download pre-req for SP1 RTM version
#                      - Added try/finally
#                      - Added option to download files from xml manifest
#                      - Changed folder for SCCM pre-req
#					   - Added option for sql version
#                      - Added option for mac client
#                      - Updated SCCM 2012 SP1 toolkit link
#                      - Updated SCCM 2012 SP1 Linux links
#
# Usage:
#		 Option 1: powershell.exe -ExecutionPolicy Bypass .\BuildMediaFolder.ps1 [Parameters]
#        Option 2: Open Powershell and execute .\BuildMediaFolder.ps1 [Parameters]
#
# Parameters: (All parameters are optional, if you do not use, script will ask you to provide the information)
#        mediaFolder - Folder where the folder structure will be created. if the folder does not exist, it will create
#        proxyauthentication - y/n - Use "y" if you need authenticate against a proxy server to download files over the net
#        username - Only used if proxyauthentication = "y" 
#        password - Only used if proxyauthentication = "y"
#        SCCM2012SP1 - Folder where the SCCM 2012 SP1 files exist (there is no validation if the file are correct or not)
#        sccmprereqinternet - y/n - use "y" if you want pre-requisites files to be downloaded from internet
#        configmgrPreReq - used if sccmprereqinternet = 'n' - folder where the pre-requisits files exist
#        ADKSetup - use Y to download the adksetup from the internet (and it will automatically be executed to download all other files) 
#                   or use a folder if you want only copy files
#                   **note, if you use a folder, all files should be already there. the adksetup.exe will only be executed if download from internet
#        ConfigMgrSDK - use Y to download the file from internet otherwise pass the folder where the file exist
#        MDT2012 - use Y to download the file from internet otherwise pass the folder where the file exist
#        SQLServerDVD - Folder where the SQL Server files exist (there is no validation if the file are correct or not)
#        KB2630458 - use Y to download the file from internet otherwise pass the folder where the file exist
#        ConfigMgrToolkit - use Y to download the file from internet otherwise pass the folder where the file exist
#        KB972455 - use Y to download the file from internet otherwise pass the folder where the file exist
#        KB2734608 - use Y to download the file from internet otherwise pass the folder where the file exist
#        linuxinternet - y/n - use "y" if you want the linux files be downloaded from internet
#        linuxfolder - used if linuxinternet = 'n' - folder where the linux files exist
#                      **note that the files does have space and if you download, remember to rename it removing the spaces
#        macclient - use Y to download the file from internet otherwise pass the folder where the file exist
#        PowerShell3 - use Y to download the file from internet otherwise pass the folder where the file exist
#		 SQLVersion - Use 2008 for 2008 R2 SP2 or 2012 for 2012 SP1
#
# Examples:
#        ./BuildMediaFolder -mediafolder "d:\CM12Automation" -proxyauthentication "y" -username "<Username>" -password "" -sccm2012sp1 "D:\Source\ConfigMgr2012\SP1" -sccmprereqinternet 'n' -configmgrPreReq 'd:\source\ConfigMgr2012\Redist' -ADKSetup 'D:\source\ConfigMgr2012\ADK' -ConfigMgrSDK 'y' -MDT2012 'y' -SQLVersion '2012' -SQLServerDVD 'D:\source\SQL2012' -ConfigMgrToolkit 'D:\source\temp' -KB972455 'D:\source\WSUS' -KB2734608 'D:\source\WSUS' -linuxinternet 'y' -PowerShell3 'D:\source\Tools' -macclient 'd:\source\macclient'
#        - will create a folder CM12Automation, will authenticate against a proxy server if IE does have proxy, with username <Username>, will ask for the password
#        - configmgr, requirements, adksetup, sql server 2012 sp1, configmgrtoolikit, wsus and powershell files are going to be copied from d:\source
#        - configmgrsdk, mdt, linux clients are going to be downloaded from internet
#=======================================================================================
#>
PARAM(
    $mediaFolder = '',
    $proxyauthentication = '',
    $username = '',
    $password = '',
    $SCCM2012SP1 = '',
    $sccmprereqinternet = '',
    $configmgrPreReq = '',
    $ADKSetup = '',
    $ConfigMgrSDK = '',
    $MDT2012 = '',
    $SQLServerDVD = '',
    $KB2630458 = '',
    $ConfigMgrToolkit = '',
    $KB972455 = '',
    $KB2734608 = '',
    $linuxinternet = '',
    $linuxfolder = '',
    $macclient = '',
    $PowerShell3 = '',
	$SQLVersion = ''
)
try
{
    $ErrorActionPreference = "Stop"
    $maxretry = 5
    $ScriptSourceFolder = (Get-Location).Path
    if ($ScriptSourceFolder -eq '') { $ScriptSourceFolder = (Get-Item (Get-Location).Path).Parent.FullName }
    if ($ScriptSourceFolder.substring($ScriptSourceFolder.length-1) -ne '\') { $ScriptSourceFolder += '\' }

    if (!(Test-Path -Path .\Functions.ps1))
    {
        Write-Host "Module Functions.ps1 does not exist on the current folder, no futher action taken" -ForegroundColor Red
        Exit
    }
    else
    {
        Import-Module -name .\Functions.ps1
    }
    $mediaFolder = (Get-Folder -return $mediaFolder -question 'Where to Build the MediaFolder structure?' -allowblank $false -errorMsg 'MediaFolder' -testfolder $false).ToLower()
    if ($mediaFolder.substring($mediaFolder.length-1) -ne '\') { $mediaFolder += '\' }

    if (!(Test-Path -Path $mediaFolder))
    {
        try
        {
            New-Item ($MediaFolder) -type directory -force | out-null 
        }
        catch
        {
            Write-Host "Unable to create $MediaFolder Folder, no futher action taken" -ForegroundColor Red
            Exit    
        }
    }

    $scriptName = ($MyInvocation.MyCommand.Name)
    $StrDateTime = Get-Date -uformat "%d%m%Y-%H%M"
    $path = $MediaFolder + "_Logs\" + ($MyInvocation.MyCommand.Name -replace '.ps1', '') + ".log"
    $component = ($MyInvocation.MyCommand.Name -replace '.ps1', '')
    New-Item ($MediaFolder + '_Logs') -type directory -force | out-null 
    try
    {
        New-Item ($MediaFolder + '_Logs\Test.log') -type file -force | out-null 
        Remove-Item ($MediaFolder + '_Logs\Test.log') -force | out-null 
    }
    catch
    {
        Write-Host "Unable to read/write file on $MediaFolder folder, no futher action taken" -ForegroundColor Red
        Exit    
    }

    [Environment]::SetEnvironmentVariable("SEE_MASK_NOZONECHECKS", "1", "Process")

    if (!(Test-PowerShell64)) { Exit }
    
    $proxyauthentication = (BuildAnswer -return $proxyauthentication -Question ("Use proxy authentication") -options "y/n" -default "n").ToLower()
    if ($proxyauthentication -eq 'y')
    {
        $return = Get-UserNamePassword -username $username -password $password -question "Enter the Proxy Authentication account" -errorMsg 'Proxy Authentication account' -testaccount $false
        $username = $return[0]
        $password = $return[1]
    }

    $SCCM2012SP1 = (Get-Folder -return $SCCM2012SP1 -Question "SCCM 2012 SP1 source folder?"  -allowblank $false -errorMsg 'SCCM2012SP1 Source folder').ToLower()
    $sccmprereqinternet = (BuildAnswer -return $sccmprereqinternet -Question ("Download SCCM 2012 SP1 pre-requirements from internet") -options "y/n" -default "n").ToLower()
    if ($sccmprereqinternet -eq 'y') { $configmgrPreReq = 'url' }
    else { $configmgrPreReq = (Get-Folder -return $configmgrPreReq -Question "SCCM 2012 SP1 Pre-requirements source folder?" -allowblank $false -errorMsg 'SCCM 2012 SP1 Pre-requirements source folder').ToLower() }

    $ADKSetup = Get-File -return $ADKSetup -filename 'adksetup.exe' -url 'http://download.microsoft.com/download/9/9/F/99F5E440-5EB5-4952-9935-B99662C3DF70/adk/adksetup.exe'
    $ConfigMgrSDK = Get-File -return $ConfigMgrSDK -filename 'ConfigMgr_SDK_2012_RTM.exe' -url 'http://download.microsoft.com/download/0/F/6/0F6C47C3-269E-4359-987D-25657A994EC9/ConfigMgr_SDK_2012_RTM.exe'

    $MDT2012 = Get-File -return $MDT2012 -filename 'MicrosoftDeploymentToolkit2012_x64.msi' -url 'http://download.microsoft.com/download/b/3/a/b3a89fae-f7bf-4e7c-b208-223b991e9c30/MicrosoftDeploymentToolkit2012_x64.msi'

	$SQLVersion = (BuildAnswer -return $SQLVersion -Question ("SQL Server Version") -options "2008/2012" -default "2008").ToLower()	
    $SQLServerDVD = (Get-Folder -return $SQLServerDVD -Question "SQL Server source folder?"  -allowblank $false -errorMsg 'SQL Server Source Folder').ToLower()
	if ($SQLVersion -eq '2008')
    { $KB2630458 = Get-File -return $KB2630458 -filename 'SQLServer2008R2SP2-KB2630458-x64-ENU.exe' -url "http://download.microsoft.com/download/3/D/C/3DC6663D-8A76-40A6-BCF2-2808C385D56A/SQLServer2008R2SP2-KB2630458-x64-ENU.exe" }

    $ConfigMgrToolkit = Get-File -return $ConfigMgrToolkit -filename 'ConfigMgr2012_Toolkit_SP1_1036.exe' -url 'http://download.microsoft.com/download/D/3/8/D3842EDD-D2AF-4035-8C0F-C07984F4134F/ConfigMgr2012_Toolkit_SP1_1036.exe'
    $PowerShell3 = Get-File -return $PowerShell3 -filename 'Windows6.1-KB2506143-x64.msu' -url 'http://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu'

    $KB972455 = Get-File -return $KB972455 -filename 'WSUS30-KB972455-x64.exe' -url 'http://download.microsoft.com/download/B/0/6/B06A69C3-CF97-42CF-86BF-3C59D762E0B2/WSUS30-KB972455-x64.exe' 
    $KB2734608 = Get-File -return $KB2734608 -filename 'WSUS-KB2734608-x64.exe' -url 'http://download.microsoft.com/download/0/2/2/0221B908-0643-4CCC-B580-2DF9C4C10749/WSUS-KB2734608-x64.exe'

    $linuxinternet = (BuildAnswer -return $linuxinternet -Question ("Download Linux Client from internet") -options "y/n" -default "n").ToLower()
    if ($linuxinternet -eq 'y') { $linuxfolder = 'url' }
    else { $linuxfolder = (Get-Folder -return $linuxfolder -Question "SCCM Linux Client folder?" -allowblank $false -errorMsg 'SCCM Linux Client folder').ToLower() }
    
    $macclient = Get-File -return $macclient -filename 'ConfigmgrMacClient.msi' -url 'http://download.microsoft.com/download/B/F/1/BF113C24-894A-47A7-826C-9A3FF2001997/ConfigmgrMacClient.msi'

    $linuxfiles = @(
    'http://download.microsoft.com/download/B/F/1/BF113C24-894A-47A7-826C-9A3FF2001997/SC%202012%20CM%20SP1%20RTM%20client%20for%20RHEL.EXE@SC2012CMSP1RTMclientforRHEL.EXE@RHEL',
    'http://download.microsoft.com/download/B/F/1/BF113C24-894A-47A7-826C-9A3FF2001997/SC%202012%20CM%20SP1%20RTM%20client%20for%20SLES.EXE@SC2012CMSP1RTMclientforSLES.EXE@SLES',
    'http://download.microsoft.com/download/B/F/1/BF113C24-894A-47A7-826C-9A3FF2001997/SC%202012%20CM%20SP1%20RTM%20client%20for%20Solaris.EXE@SC2012CMSP1RTMclientforSolaris.EXE@SOLARIS'
    )
    
    $cabfiles = @(
    'http://go.microsoft.com/fwlink/?LinkID=269721@ConfigMgr.LN.Manifest.cab',
    'http://go.microsoft.com/fwlink/?LinkId=269720@ConfigMgr.Manifest.cab'
    )
    
    $configmgrreqfiles = @()

    CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1'
    CopyOrDownload -source $SCCM2012SP1 -destination ($mediaFolder + 'ConfigMgr2012\SP1')

    if ($configmgrPreReq -eq 'url')
    {
        CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Server'
        CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Client'
        CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\MobileDevice'
        
        foreach ($file in $cabfiles)
        {
            $arrFile = $file.split('@')
            CopyOrDownload -source ($arrFile[0]) -destination ($mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist') -filename ($arrFile[1]) -username $username -password $password
            
            $xmlFileName = $arrFile[1] -replace '.cab', '.xml'
            
            Run-CommandLine -commandline ($env:windir + "\system32\expand.exe") -parameters ('-r ' + $mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\' + $arrFile[1] + ' -F:*.xml ' + $env:TEMP)
            [xml]$manifest = gc ($env:TEMP + '\' + $xmlFileName)
            foreach ($group in $manifest.ConfigMgr.Group)
            {
                foreach ($file in $group.File)
                { 
                    $configmgrreqfiles +=  ($file.Source + "@" + $file.CopyName)
                }
            }
            Remove-Item ($env:TEMP + '\' + $xmlFileName) -ErrorAction SilentlyContinue
        }

        foreach ($file in $configmgrreqfiles)
        {
            $arrFile = $file.split('@')
            CopyOrDownload -source ($arrFile[0]) -destination ($mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist') -filename ($arrFile[1]) -username $username -password $password
        }
        
        if (Test-Path -Path ($MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\MobileDevice\ConfigMgr.MobileDevice.manifest.xml' ))
        { Write-Log -message ("Ignoring extracting file ConfigMgr.MobileDevice.manifest.cab as it has already been extracted") -severity 2 }
        else
        { Run-CommandLine -commandline ($env:windir + "\system32\expand.exe") -parameters ('-r ' + $mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\MobileDevice.cab -F:*.* ' + $MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\MobileDevice') }
        
        $sourcefiles = Get-ChildItem ($MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist') -Filter client*.cab
        foreach ($file in $sourcefiles)
        {            
            $foldername = (($file.Name -replace 'client_', '') -replace '.cab', '')
            CreateFolder -rootfolder $MediaFolder -folder ('ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Client\' + $foldername)
            if (Test-Path -Path ($MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Client\' + $foldername + '\ConfigMgr.Client.' + $folderName + '.manifest.xml' ))
            { Write-Log -message ("Ignoring extracting file $($file.Name) as it has already been extracted") -severity 2 }
            else
            { Run-CommandLine -commandline ($env:windir + "\system32\expand.exe") -parameters ('-r ' + $mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\' + $file.Name + ' -F:*.* ' + $MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Client\' + $foldername) }
        }        
        
        $sourcefiles = Get-ChildItem ($MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist') -Filter server*.cab
        foreach ($file in $sourcefiles)
        {            
            $foldername = (($file.Name -replace 'server_', '') -replace '.cab', '')
            CreateFolder -rootfolder $MediaFolder -folder ('ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Server\' + $foldername)
            if (Test-Path -Path ($MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Server\' + $foldername + '\ConfigMgr.Server.' + $folderName + '.manifest.xml' ))
            { Write-Log -message ("Ignoring extracting file $($file.Name) as it has already been extracted") -severity 2 }
            else
            { Run-CommandLine -commandline ($env:windir + "\system32\expand.exe") -parameters ('-r ' + $mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\' + $file.Name + ' -F:*.* ' + $MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LanguagePack\Server\' + $foldername) }
        }        
    }
    else
    {
        CopyOrDownload -source $configmgrPreReq -destination ($mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist')
    }
    
    CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\ADK'
    if ($ADKSetup.indexof('http://') -ge 0)
    {
    	CopyOrDownload -source $ADKSetup -destination ($env:TEMP) -filename 'adksetup.exe'
        Run-CommandLine -commandline ($env:temp + "\adksetup.exe") -parameters ('/layout ' + $mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\ADK /q /log ' + $MediaFolder + '_Logs\adksetup.log')
    	Remove-Item ($env:temp + "\adksetup.exe")
    }
    else
    {
    	CopyOrDownload -source $ADKSetup -destination ($mediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\ADK')
    }

    CreateFolder -rootfolder $MediaFolder -folder 'DLLs'
    if (Test-Path -Path ($mediaFolder + "dlls\tsmediaapi.dll"))
    {
        Write-Log -message ("Ignoring copy to " + $mediaFolder + "dlls\tsmediaapi.dll") -severity 2
    }
    else
    {
        CopyOrDownload -source $ConfigMgrSDK -destination ($env:TEMP) -filename 'ConfigMgr_SDK_2012_RTM.exe'
        Run-CommandLine -commandline ($env:temp + "\ConfigMgr_SDK_2012_RTM.exe") -parameters ('/auto')
        Run-CommandLine -commandline ("msiexec.exe") -parameters ("/a C:\ConfigMgr_SDK_2012_RTM\Configuration_Manager_2012_SDK_Setup.msi /qn targetdir=C:\ConfigMgr_SDK_2012_RTM\1")
        CopyOrDownload -source "C:\ConfigMgr_SDK_2012_RTM\1\Redistributables\amd64" -destination ($mediaFolder + "DLLs") -filename 'tsmediaapi.dll'
        Remove-Item C:\ConfigMgr_SDK_2012_RTM -force -recurse
        Remove-Item ($env:temp + "\ConfigMgr_SDK_2012_RTM.exe")
    }

    CreateFolder -rootfolder $MediaFolder -folder 'MDT'
    CopyOrDownload -source $MDT2012 -destination ($mediaFolder + 'MDT') -filename 'MicrosoftDeploymentToolkit2012_x64.msi'

    CreateFolder -rootfolder $MediaFolder -folder 'Scripts'
    CopyOrDownload -source $ScriptSourceFolder -destination ($mediaFolder + 'Scripts') -forcecopy $true

    CreateFolder -rootfolder $MediaFolder -folder 'SQLServer\DVD'
    CopyOrDownload -source $SQLServerDVD -destination ($mediaFolder + 'SQLServer\DVD')
	if ($SQLVersion -eq '2008')
    { CopyOrDownload -source $KB2630458 -destination ($mediaFolder + 'SQLServer') -filename 'SQLServer2008R2SP2-KB2630458-x64-ENU.exe' }

    CreateFolder -rootfolder $MediaFolder -folder 'Tools'
    if (Test-Path -Path ($mediaFolder + "tools\ConfigMgrTools.msi"))
    {
        Write-Log -message ("Ignoring copy to " + $mediaFolder + "tools\ConfigMgrTools.msi as it already exist") -severity 2
    }
    else
    {
        CopyOrDownload -source $ConfigMgrToolkit -destination ($env:temp) -filename 'ConfigMgr2012_Toolkit_SP1_1036.exe'
        Run-CommandLine -commandline ($env:temp + "\ConfigMgr2012_Toolkit_SP1_1036.exe") -parameters ('/auto')
        CopyOrDownload -source "C:\ConfigMgr2012_Toolkit_SP1_1036\" -destination ($mediaFolder + "tools") -filename 'ConfigMgrTools.msi'
        Remove-Item C:\ConfigMgr2012_Toolkit_SP1_1036 -force -recurse
        Remove-Item ($env:temp + "\ConfigMgr2012_Toolkit_SP1_1036.exe")
    }

    CopyOrDownload -source $PowerShell3 -destination ($mediaFolder + 'tools') -filename 'Windows6.1-KB2506143-x64.msu'

    CreateFolder -rootfolder $MediaFolder -folder 'WSUS'
    CopyOrDownload -source $KB972455 -destination ($mediaFolder + 'WSUS') -filename 'WSUS30-KB972455-x64.exe' -username $username -password $password
    CopyOrDownload -source $KB2734608 -destination ($mediaFolder + 'WSUS') -filename 'WSUS-KB2734608-x64.exe' -username $username -password $password

    CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\LinuxClient'
    if ($linuxfolder -eq 'url')
    {
        foreach ($file in $linuxfiles)
        {
            $arrFile = $file.split('@')
            CreateFolder -rootfolder $MediaFolder -folder ('ConfigMgr2012\SP1\SMSSETUP\Redist\LinuxClient\' + ($arrFile[2]))
            
            CopyOrDownload -source ($arrFile[0]) -destination ($env:temp) -filename ($arrFile[1]) -username $username -password $password
            Run-CommandLine -commandline ('"' + $env:temp + "\" + $arrFile[1] + '"') -parameters ('/T:"' + $MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LinuxClient\' + $arrFile[2] + '" /C /Q')
            Remove-Item ($env:temp + "\" + $arrFile[1])
        }
    }
    else
    {
        foreach ($file in $linuxfiles)
        {
            $arrFile = $file.split('@')
            if ($linuxfolder.substring($linuxfolder.length-1) -ne '\') { $linuxfolder += '\' }
            CreateFolder -rootfolder $MediaFolder -folder ('ConfigMgr2012\SP1\SMSSETUP\Redist\LinuxClient\' + ($arrFile[2]))
            
            Run-CommandLine -commandline ('"' + $linuxfolder + "\" + $arrFile[1] + '"') -parameters ('/T:"' + $MediaFolder + 'ConfigMgr2012\SP1\SMSSETUP\Redist\LinuxClient\' + $arrFile[2] + '" /C /Q')
        }
    }
    
    CreateFolder -rootfolder $MediaFolder -folder 'ConfigMgr2012\SP1\SMSSETUP\Redist\MacClient'
    CopyOrDownload -source $macclient -destination ($env:temp) -filename 'ConfigmgrMacClient.msi' -username $username -password $password
    Run-CommandLine -commandline ("msiexec.exe") -parameters ("/a " + ($env:temp) + "\ConfigmgrMacClient.msi /qn targetdir=" + $MediaFolder + "ConfigMgr2012\SP1\SMSSETUP\Redist\MacClient")
    Remove-Item ($MediaFolder + "ConfigMgr2012\SP1\SMSSETUP\Redist\MacClient\ConfigmgrMacClient.msi")
    Remove-Item ($env:temp + "\ConfigmgrMacClient.msi")
    
    [Environment]::SetEnvironmentVariable("SEE_MASK_NOZONECHECKS", "0", "Process")

    Write-Log -Message ("Folder $MediaFolder created")
}
finally
{
    $module = Get-Module -name Functions | where-object {$_.ModuleType -eq "Script"}
    if ($module -ne $null) 
    { 
        if ($module.Path.ToLower() -eq ($MediaFolder.ToLower() + "scripts\functions.ps1")) { Remove-Module $module }
    }
}